package cn.zz.veggie.application.assembler;

import cn.zz.veggie.application.packer.ProductPacker;
import cn.zz.veggie.application.packer.ShopPacker;
import cn.zz.veggie.model.domain.Product;
import cn.zz.veggie.model.domain.Shop;
import cn.zz.veggie.model.domain.ShopQuote;
import cn.zz.veggie.model.query.ShopQuoteQuery;
import cn.zz.veggie.web.types.dto.mgmt.quote.MgmtShopQuoteQueryDto;
import cn.zz.veggie.web.types.dto.mgmt.quote.MgmtShopQuoteSaveDto;
import cn.zz.veggie.web.types.vo.mgmt.quote.MgmtShopQuoteVo;

import java.util.Collection;
import java.util.Optional;

/**
 * @author zhongq
 * @since 2024/7/28
 */
public class ShopQuoteAssembler {

	public static ShopQuote create(Integer id, Integer shopId, Integer productId, Integer price) {
		final ShopQuote quote = new ShopQuote();

		return quote;
	}

	public static ShopQuoteQuery buildQuery(MgmtShopQuoteQueryDto dto, Collection<Integer> productIds) {
		final ShopQuoteQuery query = new ShopQuoteQuery();
		query.shopId = dto.getShopId();
		query.productIds = productIds;
		return query;
	}

	public static MgmtShopQuoteVo toMgmtShopQuoteVo(ShopQuote quote, Shop shop, Product product) {
		final MgmtShopQuoteVo vo = new MgmtShopQuoteVo();
		vo.setId(quote.getId());
		vo.setShop(ShopPacker.toIdName(shop));
		vo.setProduct(ProductPacker.toHisProductVo(product));
		vo.setPrice(quote.getPrice());
		vo.setCreatedAt(quote.getCreatedAt());
		vo.setUpdatedAt(quote.getUpdatedAt());
		return vo;
	}

	public static ShopQuote createOrUpdate(ShopQuote quote, MgmtShopQuoteSaveDto dto) {
		final ShopQuote shopQuote = Optional.ofNullable(quote).orElseGet(ShopQuote::new);
		shopQuote.setProductId(dto.getProductId());
		shopQuote.setShopId( dto.getShopId());
		shopQuote.setPrice(dto.getPrice());
		return shopQuote;
	}
}